package cn.ultrarisk.scadmin.manager.biz.solr.entity;

import cn.ultrarisk.scadmin.manager.biz.solr.context.SolrState;
import cn.ultrarisk.mybatis.extension.annotation.Table;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


/**
 * solr集合分片实体类
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/4/14
 * @since V1.0
 */
@Table(table = "solr_shard", idColumn = SolrShard.ID, autoIncrement = true)
public class SolrShard implements Serializable {
    private static final long serialVersionUID = -4712333327123853980L;

    public final static String ID = "id";
    public final static String NAME = "name";
    public final static String STATE = "state";
    public final static String COLLECTION_ID = "collection_id";
    public final static String AVAILABLE = "available";
    public final static String UPDATE_TIME = "update_time";

    public static final Map<String, String> COLUMN_PROPERTY_MAP = new LinkedHashMap<String, String>();

    static {
        COLUMN_PROPERTY_MAP.put(ID, "id");
        COLUMN_PROPERTY_MAP.put(NAME, "name");
        COLUMN_PROPERTY_MAP.put(STATE, "state");
        COLUMN_PROPERTY_MAP.put(COLLECTION_ID, "collectionId");
        COLUMN_PROPERTY_MAP.put(AVAILABLE, "available");
        COLUMN_PROPERTY_MAP.put(UPDATE_TIME, "updateTime");
    }

    public SolrShard() {
    }

    public SolrShard(String name, Integer collectionId) {
        this.name = name;
        this.collectionId = collectionId;
    }

    /**
     * id
     */
    private Integer id;
    /**
     * 分片名称
     */
    private String name;
    /**
     * 状态
     */
    private SolrState state;
    /**
     * 集合id
     */
    private Integer collectionId;
    /**
     * 是否有效
     */
    private Boolean available;
    /**
     * 更新时间
     */
    private Long updateTime;
    /**
     * 副本
     */
    private List<SolrReplica> replicas;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public SolrState getState() {
        return state;
    }

    public void setState(SolrState state) {
        this.state = state;
    }

    public Integer getCollectionId() {
        return collectionId;
    }

    public void setCollectionId(Integer collectionId) {
        this.collectionId = collectionId;
    }

    public Boolean getAvailable() {
        return available;
    }

    public void setAvailable(Boolean available) {
        this.available = available;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    public List<SolrReplica> getReplicas() {
        return replicas;
    }

    public void setReplicas(List<SolrReplica> replicas) {
        this.replicas = replicas;
    }

    public void addReplica(SolrReplica replica) {
        if (this.replicas == null) {
            this.replicas = new ArrayList<SolrReplica>();
        }
        this.replicas.add(replica);
    }
}